//package com.example.behaviour.handler;
//
//
//import com.alibaba.fastjson.JSONObject;
//import com.example.behaviour.message.ChatRequestMessage;
//import com.example.behaviour.message.LoginRequestMessage;
//import com.example.behaviour.message.LoginResponseMessage;
//
//import com.example.behaviour.pojos.Message;
//import com.example.behaviour.service.UserServiceFactory;
//import com.example.behaviour.session.SessionFactory;
//import io.netty.channel.ChannelHandler;
//import io.netty.channel.ChannelHandlerContext;
//import io.netty.channel.SimpleChannelInboundHandler;
//import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
//import io.netty.util.ReferenceCountUtil;
//import lombok.extern.slf4j.Slf4j;
//
//import javax.annotation.PostConstruct;
//import javax.xml.soap.Text;
//
////@ChannelHandler.Sharable
//@Slf4j
//public class LoginRequestMessageHandler extends SimpleChannelInboundHandler<TextWebSocketFrame> {
//
//    @Override
//    protected void channelRead0(ChannelHandlerContext ctx, TextWebSocketFrame msg) throws Exception {
//        log.info("执行到了LoginRequestMessageHandler");
////        String username = msg.getUsername();
//        JSONObject jsonObject = JSONObject.parseObject(msg.text());
////        LoginRequestMessage loginRequestMessage = JSONObject.toJavaObject(jsonObject,LoginRequestMessage.class);
////        System.out.println("loginRequestMessage "+loginRequestMessage);
//
//        Message message = JSONObject.toJavaObject(jsonObject,Message.class);
//
//        if(SessionFactory.getSession().getChannel(message.getUsername()) == null){
//            SessionFactory.getSession().bind(ctx.channel(),message.getUsername());
//            LoginResponseMessage loginResponseMessage = new LoginResponseMessage(true, "登录成功,您的登录账号是："+message.getUsername());
//            TextWebSocketFrame frame = new TextWebSocketFrame(JSONObject.toJSONString(loginResponseMessage));
//            try {
//                frame.retain();
//                ctx.writeAndFlush(frame);
//            }catch (Exception e){
//                e.printStackTrace();
//            }
//
//        }
//
//        msg.retain();
//        ctx.fireChannelRead(msg);
////        ReferenceCountUtil.release(msg);
//    }
//}
